//
//  SLNewViPCollectionViewCell.m
//  StarLight
//
//  Created by apple on 16/7/30.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLNewViPCollectionViewCell.h"

@interface SLNewViPCollectionViewCell ()

@property (nonatomic ,strong) UIImageView *userImg;

@property (nonatomic ,strong) UILabel *userTypeName;

@property (nonatomic ,strong) UILabel *userName;

@property (nonatomic ,strong) UIButton *userBackImg;

@property (nonatomic ,strong) UILabel *userVIP;

@property (nonatomic ,strong) UIImageView *userVIPImg;

@property (nonatomic ,strong) UILabel *userActivityNum;

@property (nonatomic ,strong) UIView *bottomLine;

@end

@implementation SLNewViPCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self addUI];
        [self addConstraints];
    }
    return self;
}
- (void)cellForData:(SLMineUserIndexModel *)model
{
    [self.userImg sd_setImageWithURL:[NSURL URLWithString:model.headPhoto] placeholderImage:IMG(@"head") options:SDWebImageRetryFailed | SDWebImageLowPriority];
    
    self.userTypeName.text = model.type == 0 ? @"船主" : @"货主";
    
    self.userName.text = model.name;
    
    if (model.role < 1) {
        [self.userVIP removeFromSuperview];
        
    }
    if (model.vitality != 3) {
        [self.userVIPImg removeFromSuperview];
    }
    self.userActivityNum.text = [@"活跃度：" stringByAppendingString:model.active];
}

- (void)showChangeHead
{
    if (self.pushSetPhoto) {
        self.pushSetPhoto();
    }
}

- (void)addUI{
    [self addSubview:self.userImg];
    [self addSubview:self.userTypeName];
    [self addSubview:self.userName];
    [self addSubview:self.userBackImg];
    [self addSubview:self.userVIP];
    [self addSubview:self.userVIPImg];
    [self addSubview:self.userActivityNum];
    [self addSubview:self.bottomLine];
}

- (void)addConstraints{
    [self.userImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(20);
        make.top.equalTo(self).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    [self.userTypeName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userImg.mas_right).with.offset(13);
        make.top.equalTo(self).with.offset(22);
        make.height.mas_equalTo(16);
    }];
    [self.userBackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).with.offset(-27);
        make.centerY.equalTo(self.userTypeName);
        make.height.mas_equalTo(22);
        
    }];
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userBackImg.mas_left).with.offset(-11);
        make.centerY.equalTo(self.userBackImg);
        make.height.mas_equalTo(14);
    }];
    
    [self.userVIP mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userTypeName);
        make.top.equalTo(self.userTypeName.mas_bottom).with.offset(21);
        make.height.mas_equalTo(9);
    }];
    [self.userVIPImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.userVIP);
        make.left.equalTo(self.userVIP.mas_right).with.offset(7);
        make.height.mas_equalTo(12);
    }];
    [self.userActivityNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.userBackImg);
        make.top.equalTo(self.userName.mas_bottom).with.offset(21);
        make.height.mas_equalTo(12);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom);
        make.width.equalTo(self);
        make.height.mas_equalTo(0.4);
        make.centerX.equalTo(self);
    }];
}

- (UIImageView *)userImg
{
    if (!_userImg) {
        _userImg = [UIImageView new];
        _userImg.image = IMG(@"WECHAT");
        _userImg.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showChangeHead)];
        [_userImg addGestureRecognizer:tapges];
    }
    return _userImg;
}

- (UILabel *)userTypeName
{
    if (!_userTypeName) {
        _userTypeName = [UILabel new];
        _userTypeName.font = sFont(16);
        _userTypeName.textColor = RGBCOLOR(38, 38, 38);
        _userTypeName.text = @"货主";
    }
    return _userTypeName;
}

- (UIButton *)userBackImg
{
    if (!_userBackImg) {
        _userBackImg = [UIButton buttonWithType:UIButtonTypeCustom];
        [_userBackImg setImage:IMG(@"ic_arrow_right") forState:(UIControlStateNormal)];
    }
    return _userBackImg;
}

- (UILabel *)userName
{
    if (!_userName) {
        _userName = [UILabel new];
        _userName.textColor = RGBCOLOR(38, 38, 38);
        _userName.font = sFont(14);
        _userName.text = @"张三";
    }
    return _userName;
}

- (UILabel *)userVIP
{
    if (!_userVIP) {
        _userVIP = [UILabel new];
        _userVIP.textColor = RGBCOLOR(238, 85, 85);
        _userVIP.font = bFont(12);
        _userVIP.text = @"VIP";
    }
    return _userVIP;
}

- (UIImageView *)userVIPImg
{
    if (!_userVIPImg) {
        _userVIPImg = [UIImageView new];
        _userVIPImg.image = IMG(@"ic_shi");
    }
    return _userVIPImg;
}

- (UILabel *)userActivityNum
{
    if (!_userActivityNum) {
        _userActivityNum = [UILabel new];
        _userActivityNum.textColor = RGBCOLOR(38, 38, 38);
        _userActivityNum.font = bFont(12);
        _userActivityNum.text = @"活跃度：20";
    }
    return _userActivityNum;
}

- (UIView *)bottomLine
{
    if (!_bottomLine) {
        _bottomLine = [UIView new];
        _bottomLine.backgroundColor = RGBCOLOR(214, 214, 214);
    }
    return _bottomLine;
}

@end
